#!/usr/bin/env bash
parent_dir=$(pwd)
echo $parent_dir
sharding_target_home=$parent_dir
tar_names=`ls | grep .tar.gz`
tar_name=${tar_names[0]}
tar_dir=${tar_name%.*.*}
link_dir=ss_home
abs_tar_dir=$parent_dir/$tar_dir
if [ -d "$abs_tar_dir" ] ; then
	echo "stop sharding first"
	sh $abs_tar_dir/bin/stop.sh
else
	echo "sharding not running"
fi

#/bin/cp -f $sharding_target_home/$sharding_target_package ./$sharding_target_package
#echo "copy from $sharding_target_home success"

rm -rf $tar_dir
rm -rf $link_dir
tar zxf ./$tar_name
ln -sf $tar_dir $link_dir
###
#res=`ls $abs_tar_dir/lib/ | grep ^opengauss-`
#if [ $? = "1" ] ; then
#	echo "copy jdbc from $parent_dir/jdbc/ to $abs_tar_dir/lib/"
#	/bin/cp -f $parent_dir/jdbc/* $abs_tar_dir/lib/
#fi
/bin/cp -f $parent_dir/jdbc/* $abs_tar_dir/lib/

cd $abs_tar_dir
rm -rf conf
ln -sf ../config conf
rm -rf bin
ln -sf ../sharding_bin bin

#sh $sharding_abs_des_home/bin/start.sh 13000
